home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3s / scanf.z / scanf
Encoding:
Text File  |  2001-04-17  |  20.1 KB  |  329 lines

  1.  
  2.  
  3.  
  4. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _ssss_cccc_aaaa_nnnn_ffff, _ffff_ssss_cccc_aaaa_nnnn_ffff, _ssss_ssss_cccc_aaaa_nnnn_ffff - convert formatted input
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_iiii_oooo_...._hhhh_>>>>
  13.      _iiii_nnnn_tttt _ssss_cccc_aaaa_nnnn_ffff_((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_ffff_oooo_rrrr_mmmm_aaaa_tttt_,,,, _...._...._...._))))_;;;;
  14.      _iiii_nnnn_tttt _ffff_ssss_cccc_aaaa_nnnn_ffff_((((_FFFF_IIII_LLLL_EEEE _****_ssss_tttt_rrrr_mmmm_,,,, _cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_ffff_oooo_rrrr_mmmm_aaaa_tttt_,,,, _...._...._...._))))_;;;;
  15.      _iiii_nnnn_tttt _ssss_ssss_cccc_aaaa_nnnn_ffff_((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_ssss_,,,, _cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_ffff_oooo_rrrr_mmmm_aaaa_tttt_,,,, _...._...._...._))))_;;;;
  16.  
  17. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  18.      _ssss_cccc_aaaa_nnnn_ffff reads from the standard input stream, _ssss_tttt_dddd_iiii_nnnn.
  19.  
  20.      _ffff_ssss_cccc_aaaa_nnnn_ffff reads from the stream _s_t_r_m.
  21.  
  22.      _ssss_ssss_cccc_aaaa_nnnn_ffff reads from the character string _s.
  23.  
  24.      Each function reads characters, interprets them according to a format,
  25.      and stores the results in its arguments.  Each expects, as arguments, a
  26.      control string, _f_o_r_m_a_t, described below and a set of pointer arguments
  27.      indicating where the converted input should be stored.  If there are
  28.      insufficient arguments for the format, the behavior is undefined.  If the
  29.      format is exhausted while arguments remain, the excess arguments are
  30.      simply ignored.
  31.  
  32.      The control string usually contains conversion specifications, which are
  33.      used to direct interpretation of input sequences.  The control string may
  34.      contain:
  35.  
  36.           1.  White-space characters (blanks, tabs, newlines, or form-feeds)
  37.               that, except in two cases described below, cause input to be
  38.               read up to the next non-white-space character.
  39.  
  40.           2.  An ordinary character (not _%%%%) that must match the next character
  41.               of the input stream.
  42.  
  43.           3.  Conversion specifications consisting of the character _%%%% or the
  44.               character sequence _%%%%_d_i_g_i_t_s_$$$$, an optional assignment suppression
  45.               character _****, a decimal digit string that specifies an optional
  46.               numerical maximum field width, an optional letter _llll (ell), _LLLL, or
  47.               _hhhh indicating the size of the receiving object, and a conversion
  48.               code.  The conversion specifiers _dddd, _iiii, and _nnnn should be preceded
  49.               by _hhhh if the corresponding argument is a pointer to _ssss_hhhh_oooo_rrrr_tttt _iiii_nnnn_tttt
  50.               rather than a pointer to _iiii_nnnn_tttt, by _llll if it is a pointer to _llll_oooo_nnnn_gggg
  51.               _iiii_nnnn_tttt or by _llll_llll if it is a pointer to a _llll_oooo_nnnn_gggg _llll_oooo_nnnn_gggg _iiii_nnnn_tttt.  Similarly,
  52.               the conversion specifiers _oooo, _uuuu, and _xxxx should be preceded by _hhhh if
  53.               the corresponding argument is a pointer to _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _ssss_hhhh_oooo_rrrr_tttt _iiii_nnnn_tttt
  54.               rather than a pointer to _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _iiii_nnnn_tttt, by _llll if it is a pointer
  55.               to _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _llll_oooo_nnnn_gggg _iiii_nnnn_tttt, or by _llll_llll if it is a pointer to a _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd
  56.               _llll_oooo_nnnn_gggg _llll_oooo_nnnn_gggg _iiii_nnnn_tttt.  The conversion specifiers _eeee, _ffff, and _gggg should be
  57.               preceded by _llll if the corresponding argument is a pointer to
  58.               _dddd_oooo_uuuu_bbbb_llll_eeee rather than a pointer to _ffff_llll_oooo_aaaa_tttt.  Finally, the conversion
  59.  
  60.  
  61.                                                                         PPPPaaaaggggeeee 1111
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  69.  
  70.  
  71.  
  72.               specifiers _eeee, _ffff, and _gggg should be preceded by _LLLL if the
  73.               corresponding argument is a pointer to _llll_oooo_nnnn_gggg _dddd_oooo_uuuu_bbbb_llll_eeee rather than a
  74.               pointer to _ffff_llll_oooo_aaaa_tttt.  The _hhhh, _llll, _llll_llll, or _LLLL modifier is ignored with
  75.               any other conversion specifier.
  76.  
  77.      A conversion specification directs the conversion of the next input
  78.      field; the result is placed in the variable pointed to by the
  79.      corresponding argument unless assignment suppression was indicated by the
  80.      character _****.  The suppression of assignment provides a way of describing
  81.      an input field that is to be skipped.  An input field is defined as a
  82.      string of non-space characters; it extends to the next inappropriate
  83.      character or until the maximum  field width, if one is specified, is
  84.      exhausted.  For all descriptors except the character _[[[[ and the character
  85.      _cccc, white space leading an input field is ignored.
  86.  
  87.      Conversions can be applied to the _n_t_h argument in the argument list,
  88.      rather than to the next unused argument.  In this case, the conversion
  89.      character _%%%% (see above) is replaced by the sequence _%%%%_d_i_g_i_t_s_$$$$ where _d_i_g_i_t_s
  90.      is a decimal integer _n, giving the position of the argument in the
  91.      argument list.  The first such argument, _%%%%_1111_$$$$, immediately follows _f_o_r_m_a_t.
  92.      The control string can contain either form of a conversion specification,
  93.      i.e., _%%%% or _%%%%_d_i_g_i_t_s_$$$$, although the two forms cannot be mixed within a
  94.      single control string.
  95.  
  96.      The conversion code indicates the interpretation of the input field; the
  97.      corresponding pointer argument must usually be of a restricted type.  For
  98.      a suppressed field, no pointer argument is given.  The following
  99.      conversion codes are valid:
  100.  
  101.      _%%%%    A single _%%%% is expected in the input at this point; no assignment is
  102.           done.
  103.  
  104.      _dddd    Matches an optionally signed decimal integer, whose format is the
  105.           same as expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_llll function
  106.           with the value 10 for the _b_a_s_e argument.  The corresponding argument
  107.           should be a pointer to integer.
  108.  
  109.      _uuuu    Matches an optionally signed decimal integer, whose format is the
  110.           same as expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_uuuu_llll function
  111.           with the value 10 for the _b_a_s_e argument.  The corresponding argument
  112.           should be a pointer to unsigned integer.
  113.  
  114.      _oooo    Matches an optionally signed octal integer, whose format is the same
  115.           as expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_uuuu_llll function with
  116.           the value 8 for the _b_a_s_e argument.  The corresponding argument
  117.           should be a pointer to unsigned integer.
  118.  
  119.      _xxxx    Matches an optionally signed hexadecimal integer, whose format is
  120.           the same as expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_uuuu_llll
  121.           function with the value 16 for the _b_a_s_e argument.  The corresponding
  122.           argument should be a pointer to unsigned integer.
  123.  
  124.  
  125.  
  126.  
  127.                                                                         PPPPaaaaggggeeee 2222
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  135.  
  136.  
  137.  
  138.      _iiii    Matches an optionally signed integer, whose format is the same as
  139.           expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_llll function with the
  140.           value 0 for the _b_a_s_e argument.  The corresponding argument should be
  141.           a pointer to integer.
  142.  
  143.      _nnnn    No input is consumed.  The corresponding argument should be a
  144.           pointer to integer into which is to be written the number of
  145.           characters read from the input stream so far by the call to the
  146.           function.  Execution of a _%%%%_nnnn directive does not increment the
  147.           assignment count returned at the completion of execution of the
  148.           function.
  149.  
  150.      _eeee,_ffff,_gggg
  151.           Matches an optionally signed floating point number, whose format is
  152.           the same as expected for the subject string of the _ssss_tttt_rrrr_tttt_oooo_dddd function.
  153.           The corresponding argument should be a pointer to floating.
  154.  
  155.      _ssss    A character string is expected; the corresponding argument should be
  156.           a character pointer pointing to an array of characters large enough
  157.           to accept the string and a terminating _\\\\_0000, which will be added
  158.           automatically.  The input field is terminated by a white-space
  159.           character.
  160.  
  161.      _SSSS    Same as _ssss except that the corresponding argument should be a _wwww_cccc_hhhh_aaaa_rrrr______tttt
  162.           pointer pointing to an array of _wwww_cccc_hhhh_aaaa_rrrr______tttt large enough to accept the
  163.           string and a terminating _\\\\_0000, which will be added automatically.
  164.  
  165.      _cccc    Matches a sequence of characters of the number specified by the
  166.           field width (1 if no field width is present in the directive).  The
  167.           corresponding argument should be a pointer to the initial character
  168.           of an array large enough to accept the sequence.  No null character
  169.           is added.  The normal skip over white space is suppressed.
  170.  
  171.      _CCCC    Same as _cccc except that the corresponding argument should be a pointer
  172.           to the initial character of an array of type _wwww_cccc_hhhh_aaaa_rrrr______tttt large enough to
  173.           accept the sequence.
  174.  
  175.      _[[[[    Matches a nonempty sequence of characters from a set of expected
  176.           characters (the _s_c_a_n_s_e_t).  The corresponding argument should be a
  177.           pointer to the initial character of an array large enough to accept
  178.           the sequence and a terminating null character, which will be added
  179.           automatically.  The conversion specifier includes all subsequent
  180.           characters in the _f_o_r_m_a_t string, up to and including the matching
  181.           right bracket (_]]]]).  The characters between the brackets (the
  182.           _s_c_a_n_l_i_s_t) comprise the scanset, unless the character after the left
  183.           bracket is a circumflex (_^^^^), in which case the scanset contains all
  184.           characters that do not appear in the scanlist between the circumflex
  185.           and the right bracket.  If the conversion specifier begins with _[[[[_]]]]
  186.           or _[[[[_^^^^_]]]], the right bracket character is in the scanlist and the next
  187.           right bracket character is the matching right bracket that ends the
  188.           specification; otherwise the first right bracket character is the
  189.           one that ends the specification.
  190.  
  191.  
  192.  
  193.                                                                         PPPPaaaaggggeeee 3333
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  201.  
  202.  
  203.  
  204.           A range of characters in the scanset may be represented by the
  205.           construct _f_i_r_s_t _---- _l_a_s_t; thus _[[[[_0000_1111_2222_3333_4444_5555_6666_7777_8888_9999_]]]] may be expressed _[[[[_0000_----_9999_]]]].
  206.           Using this convention, _f_i_r_s_t must be lexically less than or equal to
  207.           _l_a_s_t, or else the dash will stand for itself. The character _---- will
  208.           also stand for itself whenever it is the first or the last character
  209.           in the scanlist.  To include the right bracket as an element of the
  210.           scanset, it must appear as the first character (possibly preceded by
  211.           a circumflex) of the scanlist and in this case it will not be
  212.           syntactically interpreted as the closing bracket.  At least one
  213.           character must match for this conversion to be considered
  214.           successful.
  215.  
  216.      _pppp    Matches an implementation-defined set of sequences, which should be
  217.           the same as the set of sequences that may be produced by the _%%%%_pppp
  218.           conversion of the _pppp_rrrr_iiii_nnnn_tttt_ffff function. The corresponding argument should
  219.           be a pointer to _vvvv_oooo_iiii_dddd. The interpretation of the input item is
  220.           implementation-defined. If the input item is a value converted
  221.           earlier during the same program execution, the pointer that results
  222.           shall compare equal to that value; otherwise, the behavior of the _%%%%_pppp
  223.           conversion is undefined.
  224.  
  225.      If an invalid conversion character follows the _%%%%, the results of the
  226.      operation may not be predictable.
  227.  
  228.      The conversion specifiers _EEEE, _GGGG, and _XXXX are also valid and behave the same
  229.      as _eeee, _gggg, and _xxxx, respectively.
  230.  
  231.      Each function allows for detection of a language-dependent decimal-point
  232.      character in the input string.  The decimal-point character is defined by
  233.      the program's locale (category _LLLL_CCCC______NNNN_UUUU_MMMM_EEEE_RRRR_IIII_CCCC).  In the _""""_CCCC_"""" locale, or in a
  234.      locale where the decimal-point character is not defined, the decimal-
  235.      point character defaults to a period (_....).
  236.  
  237.      The _ssss_cccc_aaaa_nnnn_ffff conversion terminates at end-of-file, at the end of the control
  238.      string, or when an input character conflicts with the control string.
  239.  
  240.      If end-of-file is encountered during input, conversion is terminated.  If
  241.      end-of-file occurs before any characters matching the current directive
  242.      have been read (other than leading white space, where permitted),
  243.      execution of the current directive terminates with an input failure;
  244.      otherwise, unless execution of the current directive is terminated with a
  245.      matching failure, execution of the following directive (if any) is
  246.      terminated with an input failure.
  247.  
  248.      If conversion terminates on a conflicting input character, the offending
  249.      input character is left unread in the input stream.  Trailing white space
  250.      (including newline characters) is left unread unless matched by a
  251.      directive.  The success of literal matches and suppressed assignments is
  252.      not directly determinable other than via the _%%%%_nnnn directive.
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.                                                                         PPPPaaaaggggeeee 4444
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  267.  
  268.  
  269.  
  270. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  271.      The call to the function _ssss_cccc_aaaa_nnnn_ffff:
  272.  
  273.           _iiii_nnnn_tttt _iiii_,,,, _nnnn_;;;; _ffff_llll_oooo_aaaa_tttt _xxxx_;;;; _cccc_hhhh_aaaa_rrrr _nnnn_aaaa_mmmm_eeee_[[[[_5555_0000_]]]]_;;;;
  274.           _nnnn _==== _ssss_cccc_aaaa_nnnn_ffff _((((_""""_%%%%_dddd_%%%%_ffff_%%%%_ssss_""""_,,,, _&&&&_iiii_,,,, _&&&&_xxxx_,,,, _nnnn_aaaa_mmmm_eeee_))))_;;;;
  275.  
  276.      with the input line:
  277.  
  278.           _2222_5555 _5555_4444_...._3333_2222_EEEE_----_1111 _tttt_hhhh_oooo_mmmm_pppp_ssss_oooo_nnnn
  279.  
  280.      will assign to _nnnn the value _3333, to _iiii the value _2222_5555, to _xxxx the value _5555_...._4444_3333_2222,
  281.      and _nnnn_aaaa_mmmm_eeee will contain _tttt_hhhh_oooo_mmmm_pppp_ssss_oooo_nnnn_\\\\_0000.
  282.  
  283.      The call to the function _ssss_cccc_aaaa_nnnn_ffff:
  284.  
  285.           _iiii_nnnn_tttt _iiii_;;;; _ffff_llll_oooo_aaaa_tttt _xxxx_;;;; _cccc_hhhh_aaaa_rrrr _nnnn_aaaa_mmmm_eeee_[[[[_5555_0000_]]]]_;;;;
  286.           _((((_vvvv_oooo_iiii_dddd_)))) _ssss_cccc_aaaa_nnnn_ffff _((((_""""_%%%%_2222_dddd_%%%%_ffff_%%%%_****_dddd _%%%%_[[[[_0000_----_9999_]]]]_""""_,,,, _&&&&_iiii_,,,, _&&&&_xxxx_,,,, _nnnn_aaaa_mmmm_eeee_))))_;;;;
  287.  
  288.      with the input line:
  289.  
  290.           _5555_6666_7777_8888_9999 _0000_1111_2222_3333 _5555_6666_aaaa_7777_2222
  291.  
  292.      will assign _5555_6666 to _iiii, _7777_8888_9999_...._0000 to _xxxx, skip _0000_1111_2222_3333, and place the characters _5555_6666_\\\\_0000
  293.      in _nnnn_aaaa_mmmm_eeee.  The next character read from _ssss_tttt_dddd_iiii_nnnn will be _aaaa.
  294.  
  295. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  296.      _cccc_cccc(1), _ssss_tttt_rrrr_tttt_oooo_dddd(3C), _ssss_tttt_rrrr_tttt_oooo_llll(3C), _pppp_rrrr_iiii_nnnn_tttt_ffff(3S).
  297.  
  298. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  299.      These routines return the number of successfully matched and assigned
  300.      input items; this number can be zero in the event of an early matching
  301.      failure between an input character and the control string.  If the input
  302.      ends before the first matching failure or conversion, _EEEE_OOOO_FFFF is returned.
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.                                                                         PPPPaaaaggggeeee 5555
  326.  
  327.  
  328.  
  329.